<?php

/**
 * Gravatar class for displaying gravatar images
 *
 */
class Gravatar extends Plugin
{
	// plugin info
	public $plugin_name = "Gravatar";
	public $plugin_short_desc = "Gravatar plugin";
	public $plugin_long_desc = "Gravat plugin displays gravatar images according to email";
	public $version = "1.0";
	public $has_sidebar = false;
	public $has_footer = false;

	/**
	 * Get either a Gravatar URL or complete image tag for a specified email address.
	 *
	 * @param string $email The email address
	 * @param string $s Size in pixels, defaults to 80px [ 1 - 512 ]
	 * @param string $d Default imageset to use [ 404 | mm | identicon | monsterid | wavatar ]
	 * @param string $r Maximum rating (inclusive) [ g | pg | r | x ]
	 * @param boole $img True to return a complete IMG tag False for just the URL
	 * @param array $atts Optional, additional key/value attributes to include in the IMG tag
	 * @return String containing either just a URL or a complete image tag
	 * @source http://gravatar.com/site/implement/images/php/
	 */
	public function get_gravatar( $email, $s = 80, $d = 'mm', $r = 'g', $img = true, $atts = array() )
	{
		$url = 'http://www.gravatar.com/avatar/';
		$url .= md5( strtolower( trim( $email ) ) );
		$url .= "?s=$s&d=$d&r=$r";
		if ( $img ) {
			$url = '<img src="' . $url . '"';
			foreach ( $atts as $key => $val )
				$url .= ' ' . $key . '="' . $val . '"';
			$url .= ' />';
		}
		return $url;
	}

	public function admin_settings()
	{
		global $core;

		$hl = $core->load_plugin('highlight');

		echo '<p>Example of usage:</p>
'.$hl->text('$plugin = $core->load_plugin(\'gravatar\');
$img = $plugin->get_gravatar(\'pirozek@mafyje.com\');
echo $img;').'<div class="hr"></div>
Output: '.$this->get_gravatar('pirozek@mafyje.com');
	}
}


?>